package com.huawei.ds.patch;

import java.io.File;
import java.util.Arrays;

import static com.huawei.ds.patch.PatchMain.MS_FULL_UPDATER_JAR;

public class PatchOptions {
    private String[] originArgs;
    private String action;
    private File tempWorkspaceDir;
    private String updaterJar;
    private String updaterJarDir;

    private String oldVersionDesc;
    private String newVersionDesc;
    private String oldVersionPath;
    private String newVersionPath;
    private String zipAsBinary;
    private String fileSet;

    private String batchDistributionDir;
    private String batchTargetDistributionVersion;
    private boolean batchOnlyToTargetDistributionVersion;

    public PatchOptions(String action, String[] args, File tempWorkspaceDir, String updaterJarDir) {
        this.originArgs = args;
        this.tempWorkspaceDir = tempWorkspaceDir;
        this.action = action;
        switch (action) {
            case "create":
                this.oldVersionDesc = args[1];
                this.newVersionDesc = args[2];
                this.oldVersionPath = args[3];
                this.newVersionPath = args[4];
                this.fileSet = args[5];
                this.zipAsBinary = args[6];
                break;
            case "batch-crate":
                this.batchDistributionDir = args[1];
                break;
            default:
        }
        this.updaterJarDir = updaterJarDir;
        this.updaterJar = updaterJarDir + "lib/" + MS_FULL_UPDATER_JAR;
    }

    private boolean hasArgument(String[] args, String name) {
        return Arrays.asList(args).contains("--" + name);
    }

    public String[] getOriginArgs() { return originArgs; }

    public void setOriginArgs(String[] originArgs) { this.originArgs = originArgs; }

    public String getAction() { return action; }

    public void setAction(String action) { this.action = action; }

    public File getTempWorkspaceDir() { return tempWorkspaceDir; }

    public void setTempWorkspaceDir(File tempWorkspaceDir) { this.tempWorkspaceDir = tempWorkspaceDir; }

    public String getOldVersionDesc() { return oldVersionDesc;}

    public void setOldVersionDesc(String oldVersionDesc) { this.oldVersionDesc = oldVersionDesc;}

    public String getNewVersionDesc() { return newVersionDesc;}

    public void setNewVersionDesc(String newVersionDesc) { this.newVersionDesc = newVersionDesc;}

    public String getOldVersionPath() { return oldVersionPath;}

    public void setOldVersionPath(String oldVersionPath) { this.oldVersionPath = oldVersionPath;}

    public String getNewVersionPath() { return newVersionPath;}

    public void setNewVersionPath(String newVersionPath) { this.newVersionPath = newVersionPath;}

    public String getZipAsBinary() { return zipAsBinary;}

    public void setZipAsBinary(String zipAsBinary) { this.zipAsBinary = zipAsBinary;}

    public String getBatchDistributionDir() { return batchDistributionDir;}

    public void setBatchDistributionDir(String batchDistributionDir) { this.batchDistributionDir = batchDistributionDir;}

    public String getBatchTargetDistributionVersion() { return batchTargetDistributionVersion;}

    public void setBatchTargetDistributionVersion(String batchTargetDistributionVersion) { this.batchTargetDistributionVersion = batchTargetDistributionVersion;}

    public String getUpdaterJarDir() { return updaterJarDir;}

    public void setUpdaterJarDir(String updaterJarDir) { this.updaterJarDir = updaterJarDir;}

    public String getUpdaterJar() { return updaterJar;}

    public void setUpdaterJar(String updaterJar) { this.updaterJar = updaterJar;}

    public boolean isBatchOnlyToTargetDistributionVersion() {
        return batchOnlyToTargetDistributionVersion;
    }

    public void setBatchOnlyToTargetDistributionVersion(boolean batchOnlyToTargetDistributionVersion) {
        this.batchOnlyToTargetDistributionVersion = batchOnlyToTargetDistributionVersion;
    }
}
